package titt.type;

import titt.util.Converter;

public class TypedObject {

	private final Type t;
	private final Object o;

	public TypedObject(Type t, Object o) {
		this.t = t;
		this.o = o;
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getObject() {
		return (T)o;
	}
	
	public Type getType() {
		return t;
	}
	
	public static final Converter<TypedObject, Class<?>> toClass = new Converter<TypedObject, Class<?>>() {
		@Override
		public Class<?> convert(TypedObject o) {
			return o.getType().asClass();
		}
	};
	public static final Converter<TypedObject, Object> toObject = new Converter<TypedObject, Object>() {
		@Override
		public Object convert(TypedObject o) {
			return o.getObject();
		}
	};

}
